



// This code is a generated code by a tool
// designed and coded by Shohdi Mohamed Elsheemy ( shohdi@gmail.com )            

using System;
using System.Collections.Generic;
using System.Web;
using System.Data.Common;
using Shohdi.DataHandler;
using System.Data;




namespace DatabaseComponent
{
    
    public partial class ExamsDB
    {
         string _Connection = "";


        public string Connection
        {
            get { return _Connection; }
            set { _Connection = value; }
        }


       
         string _Provider = "System.Data.SqlClient";

        
        public string Provider
        {
            get { return _Provider; }
            set { _Provider = value; }
        }



        public ExamsDB()
        {
        }

        public ExamsDB(string __Connection,params string [] __Provider)
        {

            if (__Provider.Length > 0)
                _Provider = __Provider[0];

            _Connection = __Connection;
            
        }




        public List<Exams> Select(ClassDataHandler con, string strTop, string strWhere, params DbParameter[] whereParams)
        {
            if (whereParams == null)
                whereParams = new DbParameter[0];

            List<Exams> lstRet = new List<Exams>();

            string strQuery = " select " + strTop  + " * from dbo.[Exams]  " ;

            if (strWhere != "")
            {
                strQuery = strQuery + "  " + strWhere;
            }

            DbDataReader dr = con.SelectDataReader(strQuery, CommandType.Text, whereParams);


            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    Exams obj = new Exams();
 if (dr["ID"] != DBNull.Value)
                    {
                        obj.ID = (System.Int64)dr["ID"];
                    }
                    else
                    {
                        obj.ID = -1;
                    } 
 if (dr["ExamIDs"] != DBNull.Value)
                    {
                        obj.ExamIDs = (System.String)dr["ExamIDs"];
                    }
                    else
                    {
                        obj.ExamIDs = "";
                    } 
 if (dr["Answers"] != DBNull.Value)
                    {
                        obj.Answers = (System.String)dr["Answers"];
                    }
                    else
                    {
                        obj.Answers = "";
                    } 
 if (dr["RegisteredCoursesID"] != DBNull.Value)
                    {
                        obj.RegisteredCoursesID = (System.Int64)dr["RegisteredCoursesID"];
                    }
                    else
                    {
                        obj.RegisteredCoursesID = -1;
                    } 



                    lstRet.Add(obj);
                   

                }
            }

            dr.Close();


            return lstRet;
        }


        public List<Exams> Select(string strTop, string strWhere, params DbParameter[] whereParams)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Exams> lstRet = Select(con, strTop, strWhere, whereParams);

            con.CloseConnection();

            return lstRet;
        }

        



        public void Insert(ClassDataHandler con , Exams obj)
        {
            
            

                    DbParameter prmExamIDs = con.createParameter();
                    prmExamIDs.ParameterName = "@ExamIDs";
                    prmExamIDs.DbType =DbType.String;
                    if (obj.ExamIDs == null)
                    {
                        prmExamIDs.Value = DBNull.Value;
                    }
                    else
                    {
                        prmExamIDs.Value = obj.ExamIDs;
                    }
                

                    


                    DbParameter prmAnswers = con.createParameter();
                    prmAnswers.ParameterName = "@Answers";
                    prmAnswers.DbType =DbType.String;
                    if (obj.Answers == null)
                    {
                        prmAnswers.Value = DBNull.Value;
                    }
                    else
                    {
                        prmAnswers.Value = obj.Answers;
                    }
                

                    


                    DbParameter prmRegisteredCoursesID = con.createParameter();
                    prmRegisteredCoursesID.ParameterName = "@RegisteredCoursesID";
                    prmRegisteredCoursesID.DbType =DbType.Int64;
                    if (obj.RegisteredCoursesID == null)
                    {
                        prmRegisteredCoursesID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmRegisteredCoursesID.Value = obj.RegisteredCoursesID;
                    }
                

                    


           



            string strQuery = " insert into dbo.[Exams] ([ExamIDs],[Answers],[RegisteredCoursesID]) VALUES (@ExamIDs,@Answers,@RegisteredCoursesID) ; select SCOPE_IDENTITY() ";
 object scope = con.ExecuteScalar(strQuery, CommandType.Text, prmExamIDs,prmAnswers,prmRegisteredCoursesID);


                    try
                    {
                        obj.ID = System.Int64.Parse(scope.ToString());
                    }
                    catch
                    {
                        obj.ID = -1;
                    }


                    


           

        }



        public void Insert(Exams obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Insert(con,obj);


            con.CloseConnection();
        }




        public void Update(ClassDataHandler con, Exams obj)
        {
            
            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


                    DbParameter prmExamIDs = con.createParameter();
                    prmExamIDs.ParameterName = "@ExamIDs";
                    prmExamIDs.DbType =DbType.String;
                    if (obj.ExamIDs == null)
                    {
                        prmExamIDs.Value = DBNull.Value;
                    }
                    else
                    {
                        prmExamIDs.Value = obj.ExamIDs;
                    }
                

                    


                    DbParameter prmAnswers = con.createParameter();
                    prmAnswers.ParameterName = "@Answers";
                    prmAnswers.DbType =DbType.String;
                    if (obj.Answers == null)
                    {
                        prmAnswers.Value = DBNull.Value;
                    }
                    else
                    {
                        prmAnswers.Value = obj.Answers;
                    }
                

                    


                    DbParameter prmRegisteredCoursesID = con.createParameter();
                    prmRegisteredCoursesID.ParameterName = "@RegisteredCoursesID";
                    prmRegisteredCoursesID.DbType =DbType.Int64;
                    if (obj.RegisteredCoursesID == null)
                    {
                        prmRegisteredCoursesID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmRegisteredCoursesID.Value = obj.RegisteredCoursesID;
                    }
                

                    


           



            string strQuery = " update dbo.[Exams] set [ExamIDs]=@ExamIDs,[Answers]=@Answers,[RegisteredCoursesID]=@RegisteredCoursesID where  [ID]=@ID  ";

            con.ExecuteNonQuery(strQuery, CommandType.Text,prmID,prmExamIDs,prmAnswers,prmRegisteredCoursesID);

            

        }


        public void Update(Exams obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Update(con, obj);


            con.CloseConnection();
        }



        public void Delete(ClassDataHandler con, Exams obj)
        {

            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


           



           



            string strQuery = " delete from dbo.[Exams]  where  [ID]=@ID  "; 
                        con.ExecuteNonQuery(strQuery, CommandType.Text,prmID );  

             



        }


        public void Delete( Exams obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            Delete(con, obj);

            con.CloseConnection();
        }





                    public List<Exams> getExamsByID(ClassDataHandler con,System.Int64 ID)
                    {
                        List<Exams> lstRet = new List<Exams>();


                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType = DbType.Int64;
                        if (ID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmID.Value = ID;
                        }


                        lstRet = Select(con, "" , " where [ID]=@ID ", prmID);



                        return lstRet;

                    }


                    public List<Exams> getExamsByID(System.Int64 ID)
                    {
                        List<Exams> lstRet = new List<Exams>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getExamsByID(con, ID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Exams> getExamsByExamIDs(ClassDataHandler con,System.String ExamIDs)
                    {
                        List<Exams> lstRet = new List<Exams>();


                        DbParameter prmExamIDs = con.createParameter();
                        prmExamIDs.ParameterName = "@ExamIDs";
                        prmExamIDs.DbType = DbType.String;
                        if (ExamIDs == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmExamIDs.Value = ExamIDs;
                        }


                        lstRet = Select(con, "" , " where [ExamIDs]=@ExamIDs ", prmExamIDs);



                        return lstRet;

                    }


                    public List<Exams> getExamsByExamIDs(System.String ExamIDs)
                    {
                        List<Exams> lstRet = new List<Exams>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getExamsByExamIDs(con, ExamIDs);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Exams> getExamsByAnswers(ClassDataHandler con,System.String Answers)
                    {
                        List<Exams> lstRet = new List<Exams>();


                        DbParameter prmAnswers = con.createParameter();
                        prmAnswers.ParameterName = "@Answers";
                        prmAnswers.DbType = DbType.String;
                        if (Answers == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmAnswers.Value = Answers;
                        }


                        lstRet = Select(con, "" , " where [Answers]=@Answers ", prmAnswers);



                        return lstRet;

                    }


                    public List<Exams> getExamsByAnswers(System.String Answers)
                    {
                        List<Exams> lstRet = new List<Exams>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getExamsByAnswers(con, Answers);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<Exams> getExamsByRegisteredCoursesID(ClassDataHandler con,System.Int64 RegisteredCoursesID)
                    {
                        List<Exams> lstRet = new List<Exams>();


                        DbParameter prmRegisteredCoursesID = con.createParameter();
                        prmRegisteredCoursesID.ParameterName = "@RegisteredCoursesID";
                        prmRegisteredCoursesID.DbType = DbType.Int64;
                        if (RegisteredCoursesID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmRegisteredCoursesID.Value = RegisteredCoursesID;
                        }


                        lstRet = Select(con, "" , " where [RegisteredCoursesID]=@RegisteredCoursesID ", prmRegisteredCoursesID);



                        return lstRet;

                    }


                    public List<Exams> getExamsByRegisteredCoursesID(System.Int64 RegisteredCoursesID)
                    {
                        List<Exams> lstRet = new List<Exams>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getExamsByRegisteredCoursesID(con, RegisteredCoursesID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

            
public List<Exams> Search(ClassDataHandler con, Exams obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID AND ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.ExamIDs != "")
                    {
                        DbParameter prmExamIDs = con.createParameter();
                        prmExamIDs.ParameterName = "@ExamIDs";
                        prmExamIDs.DbType =DbType.String;
                        if (obj.ExamIDs == null)
                        {
                            prmExamIDs.Value = DBNull.Value;
                        }
                        else
                        {
                            prmExamIDs.Value = obj.ExamIDs;
                        }
                        strWhere += " [ExamIDs]=@ExamIDs AND ";
                        lstParameters.Add(prmExamIDs);
                     }



                    

                    if (obj.Answers != "")
                    {
                        DbParameter prmAnswers = con.createParameter();
                        prmAnswers.ParameterName = "@Answers";
                        prmAnswers.DbType =DbType.String;
                        if (obj.Answers == null)
                        {
                            prmAnswers.Value = DBNull.Value;
                        }
                        else
                        {
                            prmAnswers.Value = obj.Answers;
                        }
                        strWhere += " [Answers]=@Answers AND ";
                        lstParameters.Add(prmAnswers);
                     }



                    

                    if (obj.RegisteredCoursesID != -1)
                    {
                        DbParameter prmRegisteredCoursesID = con.createParameter();
                        prmRegisteredCoursesID.ParameterName = "@RegisteredCoursesID";
                        prmRegisteredCoursesID.DbType =DbType.Int64;
                        if (obj.RegisteredCoursesID == null)
                        {
                            prmRegisteredCoursesID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmRegisteredCoursesID.Value = obj.RegisteredCoursesID;
                        }
                        strWhere += " [RegisteredCoursesID]=@RegisteredCoursesID AND ";
                        lstParameters.Add(prmRegisteredCoursesID);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("AND"));

                    

            

            List<Exams> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<Exams> Search(Exams obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Exams> lstRet = Search(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                

            
public List<Exams> SearchOrLike(ClassDataHandler con, Exams obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID OR ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.ExamIDs != "")
                    {
                        DbParameter prmExamIDs = con.createParameter();
                        prmExamIDs.ParameterName = "@ExamIDs";
                        prmExamIDs.DbType =DbType.String;
                        if (obj.ExamIDs == null)
                        {
                            prmExamIDs.Value = DBNull.Value;
                        }
                        else
                        {
                            prmExamIDs.Value = obj.ExamIDs;
                        }
                        strWhere += " [ExamIDs] LIKE @ExamIDs OR ";
                        lstParameters.Add(prmExamIDs);
                     }



                    

                    if (obj.Answers != "")
                    {
                        DbParameter prmAnswers = con.createParameter();
                        prmAnswers.ParameterName = "@Answers";
                        prmAnswers.DbType =DbType.String;
                        if (obj.Answers == null)
                        {
                            prmAnswers.Value = DBNull.Value;
                        }
                        else
                        {
                            prmAnswers.Value = obj.Answers;
                        }
                        strWhere += " [Answers] LIKE @Answers OR ";
                        lstParameters.Add(prmAnswers);
                     }



                    

                    if (obj.RegisteredCoursesID != -1)
                    {
                        DbParameter prmRegisteredCoursesID = con.createParameter();
                        prmRegisteredCoursesID.ParameterName = "@RegisteredCoursesID";
                        prmRegisteredCoursesID.DbType =DbType.Int64;
                        if (obj.RegisteredCoursesID == null)
                        {
                            prmRegisteredCoursesID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmRegisteredCoursesID.Value = obj.RegisteredCoursesID;
                        }
                        strWhere += " [RegisteredCoursesID]=@RegisteredCoursesID OR ";
                        lstParameters.Add(prmRegisteredCoursesID);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("OR"));

                    

            

            List<Exams> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<Exams> SearchOrLike(Exams obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<Exams> lstRet = SearchOrLike(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                
        


       
        



    }
}











            